/***************** Modification History ***********************************
   @doc
   @module report1.c - Application Report functions |
   @end

$Log: /SoftPay/SPK2SIM/Source/Batch/report1.c $
**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/
#include <project.h>

#ifdef BATCH_DEFINED
#define VSREPT1_C

#include <aclconio.h>
#include <stdlib.h>
#include <stdio.h>
#include <applidl.h>
#include <svctxo.h>
#include <aclstr.h>
#include <dbmgr.h>
#include <formater.h>
#include <string.h>
#include <actutil.h>


/** /#define DEBUG_VSREPORT*/
#ifdef DEBUG_VSREPORT
#define DEBUG_95
#endif

#include <define.h>
#include <transact.h>
#include <report.h>
#include <bdt.h>
#include <cdt.h>
#include <cst.h>
#include <tblutil.h>
#include <hdt.h>
#include <lct.h>
#include <tct.h>
#include <pct.h>
#include <sdt.h>
#include <iit.h>
#include <confio.h>
#include <format.h>
#include <mdlfuncs.h>
#include <merch.h>
#include <msg.h>
#include <msgfuncs.h>
#include <msgclrk.h>
#include <print.h>
#include <tran.h>
#include <ui.h>
#include <form.h>
#include <form2.h>
#include <date.h>
#include <settlbat.h>
#include <mit.h>
#include <rcptcmpt.h>
#include <rcptsegs.h>
#include <spdebug.h>
#include <batmsg.h>
#include <pbatch.h>
#include <trt.h>
#include <pform.h>

/*
 *      Static function prototypes
 */
static void vdSetDetailHeaderCondition(int inReportTop,int inCurrencyFlag);
static int inPrintDetailReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter);
static void vdMakeOpenTabMiddle(TRANSACTION_OBJECT* pobTran);
static int inPrintDetailMiddle(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran,DETAIL_TOTALS* psrDetTot);
static void vdSetOpenTabHeaderCondition(int inReportType);
static void vdSetOpenTabBottomCondition(int inCount);
static int inPrintOpenTabReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter);
static int inReprintRecpt(long lnInvNum,PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran);

/*********************************************************************************************
* @func static void | vdSetDetailHeaderCondition |
*
*       Sets 'lnHeaderCondition' for Detail Report header.
*
* @parm int     | inReportTop   |
*
* @rdesc VOID
*
* @end
**********************************************************************************************/

static void vdSetDetailHeaderCondition(int inReportTop,int inCurrencyFlag) {
    if (inGetPrinterType() == NOPRINTER || !fGetEnablePrinter())
        return;
    lnHeaderCondition = formater_set_flags(inReportTop, (inReportTop && fGetDemoMode() == VS_TRUE), (fGetCashBack()), (inGetTipProcessing() > TIP_OFF),

        (inGetApplicationType() == RETAIL && inGetClerkMode() != NO_CLERK),
        (inGetApplicationType() == RETAIL && inGetClerkMode() == NO_CLERK),
        (inGetApplicationType() == RESTAURANT && inGetClerkMode() != NO_CLERK),
        (inGetApplicationType() == RESTAURANT && inGetClerkMode() == NO_CLERK),

        inGetMITTotRecs() > 1,
        0,
        0,
        0,

        (inGetShiftType() != NO_SHIFT),
        (inGetCSTTotRecs() > 1 && inCurrencyFlag == VS_TRUE),
        0,
        0,

        0,
        0,
        0,
        0,

        (inGetTipProcessing() > TIP_OFF && fGetCashBack()),
        (inGetTipProcessing() > TIP_OFF && !(fGetCashBack())),
        (inGetTipProcessing() == TIP_OFF && fGetCashBack()),
        (inGetTipProcessing() == TIP_OFF && !(fGetCashBack())),

        0,
        0,
        0,
        0,

        0,
        0,
        0,
        0, -1);
}

/*********************************************************************************************
* @func static int | inPrintDetailReport |
*
*       Browes through the batch and print the detail report.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
* @parm PRINTER_OBJECT *    | obPrinter |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

static int inPrintDetailReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter) {
    int inNewCurr,
    inReportTop = VS_TRUE;
    int inResult,
    inNeedGrTot,
    inCnt = 0;
    int inNeedCurrTot,
    inCurr = 0;

    int inNumberOfRecordsinBatch;
    int inPrintDetail = VS_FALSE;
    int inStart,
    inStop,
    inNumberOfMerchants,
    inMerch = 0;
    int inHostIndex;
    int inCurrencyFlag = VS_FALSE;
    int inCurrencyIndex = VS_ERR;
    unsigned char ucTempHDTRec[SIZE_HDT_REC + 1];
    //HDT_REC srTempHDTRec;
    /* Grand total accumulators */
    DETAIL_TOTALS srGrTot;
    /* Currency total accumulators */
    DETAIL_TOTALS srCurrTot;

    /** /pdebug(("--inPrintDetailReport--"));*/

    for (inHostIndex = 0; inHostIndex < MAX_HOSTS; inHostIndex++) {
        if (inLoadHDTRecFromStruct(inHostIndex, ucTempHDTRec) != VS_SUCCESS) {
            vdSGErrorMessage(HDT_ERR_MSG21);
            return(VS_ERR);
        }

        if (fGetAllowMultiCurrencyFromStruct(ucTempHDTRec)) {
            inCurrencyFlag = VS_TRUE;
            break;
        }

        /* If the hosts are using different currencies then show it, */
        /* regardless of the multi currency flag */
        if (fGetIndependentBatchFromStruct(ucTempHDTRec)) {
            if (inCurrencyIndex == VS_ERR) /* not been set yet */
                inCurrencyIndex = inGetCurrencyIdxFromStruct(ucTempHDTRec);
            else {
                if (inCurrencyIndex != inGetCurrencyIdxFromStruct(ucTempHDTRec))
                    inCurrencyFlag = VS_TRUE;
            }
        } /* end if Independent Batch */
    } /* end for MAX_HOSTS in HDT */

    if (fChkAllHostBatches(pobTran)) {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    /* determine how many merchants should be printed */
    inNumberOfMerchants = inSelectOneAllMID(pobTran, fGetMultiMerchPrompt());
    if (inNumberOfMerchants == 0)
        return(VS_SUCCESS);
    if (inNumberOfMerchants == inGetMITTotRecs()) {
        inStart = 1;
        inStop = inGetMITTotRecs();
    } else if (inNumberOfMerchants == 1) {
        inStart = inGetMerchantNum();
        inStop = inGetMerchantNum();
    } else {
        inStart = 1;
        inStop = 0;
    }

    for (inMerch = inStart; inMerch <= inStop; inMerch++) {
        if (inLoadMITRec(inMerch - 1) != VS_SUCCESS)
            return(VS_ERR);
        strlcpy(srRcpt.szMerchantName, szGetMerchantText(), MESSAGE_SIZE);

        inZeroDetailTotals(&srGrTot);
        inNeedGrTot = 0;  /* bb1 */

        inNumberOfRecordsinBatch = inGetDCBatchRecCnt(pobTran);
        /* Check whether the batch is empty or not */
        if (inNumberOfRecordsinBatch == 0) {
            //vdDisplayMessageFromFile( SKIP_MSG, STATUS_MSG);
            vdCloseDCBatch(pobTran); /* bb1 */
        } else /* bb1 */ {
            /* bb1 */

            /* Need this for inGetDCKeyBatchRec() below */
            vdBatchDCOpen(pobTran);

            if (fGetEnablePrinter())
                vdDisplayMessageFromFile(PRINTING_MSG, STATUS_MSG);

            memset(srRcpt.unFrm.srReceipt.szSChg, 0x00, sizeof(srRcpt.unFrm.srReceipt.szSChg));

            vdMakeReportHeader(pobTran);
            inPrintReportHeader(pobTran, obPrinter);
            inNeedCurrTot = 0;
            for (inCurr = 0; inCurr < inGetCSTTotRecs(); inCurr++) {
                if (inLoadCSTRec(inCurr) != VS_SUCCESS) {
                    vdCloseDCBatch(pobTran);
                    vdSGErrorMessage(CST_ERR_MSG);
                    return(VS_ERR);
                }
                inCnt = 0;
                inZeroDetailTotals(&srCurrTot);
                pobTran->srBKey.inCurrencyIndex = inCurr;
                strcpy(srRcpt.unFrm.srDet.srMid.szCSymbol, szGetCurSymbol());

                inNewCurr = VS_TRUE;

                srRcpt.unFrm.srDet.srMid.inTotalTipCount = 0; /* mb1 */
                srRcpt.unFrm.srDet.srMid.lnTotalTipAmt = 0;   /* mb1 */

                /* Print online records */
                if ((inResult = inGetDCKeyBatchRec(pobTran, KEY_CURRENCY, &pobTran->srBKey, DB_FIRST)) == VS_SUCCESS)
                    do {
                        if (inGGCode() != AUTH_ONLY && inGGCode() != IMAM_CARDVER) {
                            if (inNewCurr) {
                                inNewCurr = VS_FALSE;
                                /* Header condition should not print report title except at top of report */
                                vdSetDetailHeaderCondition(inReportTop, inCurrencyFlag);
                                inReportTop = VS_FALSE;

#ifdef CLERK_DEFINED
                                if (inGetClerkMode() == NO_CLERK)
                                    strcpy(srRcpt.szClerkId, " ");
                                else if (inGetApplicationType() == RETAIL)
                                                                                                        /* lmw 1/28/99 use Message file --not hard coded label
                                                                                                        strcpy(srRcpt.szClerkId, "Clrk");*/
                                    vdGetMessageFromFile(RPT_CLERK_MSG4, srRcpt.szClerkId);
                                else
                                                                                                        /* lmw 1/28/99 use Message file --not hard coded label
                                                                                                        strcpy(srRcpt.szClerkId, "Srvr");*/
                                    vdGetMessageFromFile(RPT_SERVER_MSG4, srRcpt.szClerkId);
#else
                                strcpy(srRcpt.szClerkId, " ");
#endif
                                if (inPrintLines(obPrinter, DETAIL_TOP_START, DETAIL_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS) {
                                    vdCloseDCBatch(pobTran);
                                    return(VS_ERR);
                                }
                            }

                            if (inPrintDetailMiddle(obPrinter, pobTran, &srCurrTot) != VS_SUCCESS) {
                                vdCloseDCBatch(pobTran);
                                return(VS_ERR);
                            }
                            inCnt++;

                            if (act_kbd_pending_test(KEY_CANCEL)) {
                                vdCloseDCBatch(pobTran);
                                return(VS_ESCAPE);
                            }
                        }
                        inResult = inGetDCKeyBatchRec(pobTran, KEY_CURRENCY, &pobTran->srBKey, DB_NEXT);
                    } while (inResult == VS_SUCCESS);
                    /* end of key */

                    /* Bottom */
                if (inCnt > 0) {
                    if (inGetCSTTotRecs() > 1 && inCurrencyFlag == VS_TRUE)
                        inNeedCurrTot++;
                    else
                        inNeedGrTot++;
                }
                inAccumDetailTotals(&srGrTot, &srCurrTot);
                srCurrTot.inVoidCnt = 0;

                if (inGetCSTTotRecs() > 1) {
                    if ((inNeedCurrTot > 0) && (inCnt > 0)) {
                        /* In CoreFix, if you remove the call to inLoadDefaultCurrency(), */
                        /* which reloads the CST with the HDT currency index, in */
                        /* inLoadCDTandCST() then the patch below is not needed.   */
                        /* inLoadCDTandCST() is called by inGetDCKeyBatchRec() above */
                        /* 08/09/00 - mdm */

                        /* The CoreFix wasn't quite made, the original inLoadCDTandCST() */
                        /* function was just renamed inLoadCardCurrenyHostData() so this */
                        /* patch is still needed for now - 08/22/00 */

                        /* Reload correct currency record for symbol due to error above */
                        if (inLoadCSTRec(inCurr) != VS_SUCCESS) {
                            vdSGErrorMessage(CST_ERR_MSG);
                            return(VS_ERR);
                        }

                        /* Currency Totals */
                        inSetDetailPrintTotals(&srCurrTot);
                        vdSetDetailBottomCondition(pobTran, inPrintDetail, inNumberOfRecordsinBatch, 1, &srCurrTot);

                        if (inPrintLines(obPrinter, DETAIL_BOTTOM_START, DETAIL_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS) {
                            vdCloseDCBatch(pobTran);
                            return(VS_ERR);
                        }
                    }
                    //                    if (inNeedCurrTot)
                    //                        inNeedGrTot++;
                }
            }/* end currency for loop */
            inPrintDetail = VS_TRUE;

            /*  Always need grand totals if NO_SHIFT */
            if (inNeedGrTot > 0) {
                /*  Use default currency for host for grand totals */
                if (inLoadCSTRec(inGetCurrencyIdx()) != VS_SUCCESS) {
                    vdCloseDCBatch(pobTran);
                    vdSGErrorMessage(CST_ERR_MSG);
                    return(VS_ERR);
                }
                /* Grand Totals */
                inSetDetailPrintTotals(&srGrTot);
                /* Param 3 indicates this is the GrandTotal bottom */
                vdSetDetailBottomCondition(pobTran, inPrintDetail, inNumberOfRecordsinBatch, 2, &srGrTot);

                if (inPrintLines(obPrinter, DETAIL_BOTTOM_START, DETAIL_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS) {
                    vdCloseDCBatch(pobTran);
                    return(VS_ERR);
                }
            } else if (inPrintLines(obPrinter, DETAIL_FORM_FEED, DETAIL_BOTTOM_END, NO_BL_LINE, 0x80000000) != VS_SUCCESS) {
                vdCloseDCBatch(pobTran);
                return(VS_ERR);
            }

            memset(srRcpt.szErrorMessage, '\0', sizeof(srRcpt.szErrorMessage));
            memset(srRcpt.szStatusMessage, '\0', sizeof(srRcpt.szStatusMessage));

            vdCloseDCBatch(pobTran); /* bb1 */
        } /* bb1 */
    } /* merchant loop */

    vdSGErrorMessage(0L); // Clear error message
    return (VS_SUCCESS);
}

/*********************************************************************************************
* @func void | vdMakeDetailMiddle |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
* @parm DETAIL_TOTALS * | psrDetTot |
*
* @rdesc VOID
*
* @end
**********************************************************************************************/

void vdMakeDetailMiddle(TRANSACTION_OBJECT* pobTran,DETAIL_TOTALS* psrDetTot) {
    int len = 0;
    long baseamt = 0L;
    int inTransType = 0;
    char acctnum[PAN_SIZE + 1];
    char invnum[INV_NUM_SIZE + 1];

    TRANSACTION_OBJECT obTran; /* bb1 */

    /* Load TRT locally for batch record */
    inLoadTRTRec(&obTran, pobTran->srBRec.inCode); /* bb1 */

    memset(acctnum, 0x00, sizeof(acctnum));
    memset(srRcpt.unFrm.srDet.srMid.szCType, 0x00, sizeof(srRcpt.unFrm.srDet.srMid.szCType));
    memset(srRcpt.szTipAmt, 0x00, sizeof(srRcpt.szTipAmt));

    memset(srRcpt.unFrm.srDet.srMid.szCashBack, 0x00, sizeof(srRcpt.unFrm.srDet.srMid.szCashBack));

    if (pobTran->srBRec.lnMessage)
        vdGetMessageFromFile(pobTran->srBRec.lnMessage, srRcpt.unFrm.srDet.srMid.szTransType);

    long2str(invnum, pobTran->srBKey.lnInvNum);
    pad(srRcpt.unFrm.srDet.srMid.szInvNum, invnum, '0', inGetInvNumSize(), RIGHT);

    strcpy(acctnum, pobTran->srBRec.szPAN);

    len = strlen(acctnum);
    strncpy(&srRcpt.unFrm.srDet.srMid.szAcctNum[0], &acctnum[len - LAST4_DIGIT_ACCT], (LAST4_DIGIT_ACCT + 1));

    strcpy(srRcpt.unFrm.srDet.srMid.szCType, szGetCardAbbrev());

    if (!pobTran->srBKey.fVoided)
        sprintf(srRcpt.unFrm.srDet.srMid.szTot, SUBSTITUTE_LD, pobTran->srBKey.lnTotalOfTransactionAmount);
    else
        strcpy(srRcpt.unFrm.srDet.srMid.szTot, "000");
    vdFormatAmount(srRcpt.unFrm.srDet.srMid.szTot, VS_FALSE);
    vdTrimLeadSpaces(srRcpt.unFrm.srDet.srMid.szTot);

    baseamt = (pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnTaxAmount - pobTran->srBRec.lnTipAmount - pobTran->srBRec.lnSChgAmount - pobTran->srBRec.lnCashBackAmount);

    /** /pdebug(("baseamt=%ld",baseamt));*/
    /** /pdebug(("Tot=%ld",pobTran->srBKey.lnTotalOfTransactionAmount));*/
    /** /pdebug(("Tax=%ld",pobTran->srBRec.lnTaxAmount));*/
    /** /pdebug(("Tip=%ld",pobTran->srBRec.lnTipAmount));*/
    /** /pdebug(("SChg=%ld",pobTran->srBRec.lnSChgAmount));*/
    /** /pdebug(("CB=%ld",pobTran->srBRec.lnCashBackAmount));*/

    if (!pobTran->srBKey.fVoided && !fRefundTrans(pobTran))
        inTransType = SALE;
    else if (fRefundTrans(pobTran) && !pobTran->srBKey.fVoided) /* bb1 */
        inTransType = REFUND;
    else
        inTransType = VOID;

    switch (inTransType) {
    case    SALE:
        psrDetTot->dbTipAmt += (double) pobTran->srBRec.lnTipAmount;
        psrDetTot->inSaleCnt++;
        psrDetTot->dbSaleAmt += (double) baseamt;
        if ((pobTran->srBRec.lnTipAmount > 0L))
            psrDetTot->inTipCnt++;
        if (pobTran->srBRec.fTaxEntered && (pobTran->srBRec.lnTaxAmount > 0L))
            psrDetTot->inTaxCnt++;                             /* bb1 */
        psrDetTot->dbTaxAmt += (double) pobTran->srBRec.lnTaxAmount;    /* bb1 */
        psrDetTot->dbGrandAmt += (double) (pobTran->srBKey.lnTotalOfTransactionAmount);
        /* Surcharge amount have value */
        if ((pobTran->srBRec.lnSChgAmount > 0L) && (HOST_NETID_TEST)) {
            psrDetTot->dbSurCharge += (double) pobTran->srBRec.lnSChgAmount;
            psrDetTot->inSurchgCnt ++;
        }
        if (pobTran->srBRec.lnTipAmount > 0L)
            sprintf(srRcpt.szTipAmt, SUBSTITUTE_LD, pobTran->srBRec.lnTipAmount);
        else
            strcpy(srRcpt.szTipAmt, "000");  /* bb1 */

        sprintf(srRcpt.szAmt, SUBSTITUTE_LD, baseamt);
        psrDetTot->inGrandCnt++;
        break;

    case    REFUND:
        psrDetTot->dbTipAmt -= (double) pobTran->srBRec.lnTipAmount;
        psrDetTot->inRefCnt++;
        psrDetTot->dbRefAmt += (double) baseamt;
        if ((pobTran->srBRec.lnTipAmount > 0L))
            psrDetTot->inTipCnt++;
        if (pobTran->srBRec.fTaxEntered && (pobTran->srBRec.lnTaxAmount > 0L))
            psrDetTot->inTaxCnt++;                             /* bb1 */
        psrDetTot->dbTaxAmt -= (double) pobTran->srBRec.lnTaxAmount;    /* bb1 */
        psrDetTot->dbGrandAmt -= (double) pobTran->srBKey.lnTotalOfTransactionAmount; /* do not add refunds*/
        if (pobTran->srBRec.lnSChgAmount > 0L) {
            psrDetTot->dbSurCharge -= (double) pobTran->srBRec.lnSChgAmount;
            psrDetTot->inSurchgCnt ++;
        }
        if (pobTran->srBRec.lnTipAmount > 0L)
            sprintf(srRcpt.szTipAmt, SUBSTITUTE_LD, pobTran->srBRec.lnTipAmount);
        else
            strcpy(srRcpt.szTipAmt, "000");

        sprintf(srRcpt.szAmt, SUBSTITUTE_LD, baseamt);
        psrDetTot->inGrandCnt++;
        break;

    case    VOID:
        strcpy(srRcpt.szAmt, "000");
        /* update void tran counts */
        ++psrDetTot->inVoidCnt;
        strcpy(srRcpt.szTipAmt, "000");
        if (pobTran->srBRec.lnCashBackAmount)
            strcpy(srRcpt.unFrm.srDet.srMid.szCashBack, "000");
        /* Do not allow VOID AutoDecrement to go neg. */
        psrDetTot->inGrandCnt = (psrDetTot->inGrandCnt > 0 ? psrDetTot->inGrandCnt-- : psrDetTot->inGrandCnt);
        break;

    default:
        break;
    }

    if (inGetTipProcessing() > TIP_OFF) {
        vdFormatAmount(srRcpt.szTipAmt, VS_FALSE);
        vdTrimLeadSpaces(srRcpt.szTipAmt);
    } else
        strcpy(srRcpt.szTipAmt, " ");

    vdFormatAmount(srRcpt.szAmt, VS_FALSE);
    vdTrimLeadSpaces(srRcpt.szAmt);
    /* pj1 - fix ITO #106 & ATL #18*/

    if (!fGetCashBack())
        strcpy(srRcpt.unFrm.srDet.srMid.szCashBack, " ");
    else {
        /*
         *      Only INC Amount and Count if CashBack was really entered.
         */
        if (pobTran->srBRec.lnCashBackAmount && inTransType != VOID) {
            psrDetTot->dbCBAmt += (double) pobTran->srBRec.lnCashBackAmount;
            psrDetTot->inCBackCnt++;
            sprintf(srRcpt.unFrm.srDet.srMid.szCashBack, SUBSTITUTE_LD, pobTran->srBRec.lnCashBackAmount);
        }
        vdFormatAmount(srRcpt.unFrm.srDet.srMid.szCashBack, VS_FALSE);
        vdTrimLeadSpaces(srRcpt.unFrm.srDet.srMid.szCashBack);
    }

    if (!pobTran->srBKey.fVoided)
        strcpy(srRcpt.unFrm.srDet.srMid.szTransType, pobTran->srBRec.szTranAbbrev);   /* jc1 */
    else {
        strcpy(srRcpt.unFrm.srDet.srMid.szTransType, "V");
        strncat(srRcpt.unFrm.srDet.srMid.szTransType, pobTran->srBRec.szTranAbbrev, 1);   /* jc1 */
    }

    /* betty_b1 */
    if (inGetClerkMode() == NO_CLERK)
        strcpy(srRcpt.szClerkId, " ");
    else
        strlcpy(srRcpt.szClerkId, pobTran->srBKey.szClerkId, CLERK_ID_SIZE);

    vdSetTranStatus(pobTran);
}

/*********************************************************************************************
* @func static void | vdMakeOpenTabMiddle |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc VOID
*
* @end
**********************************************************************************************/

static void vdMakeOpenTabMiddle(TRANSACTION_OBJECT* pobTran) {
    char cardname[25];
    long realbase = 0L;
    int len = 0;
    char acctnum[PAN_SIZE + 1];

    memset(cardname, 0, sizeof(cardname));
    memset(srRcpt.unFrm.srOTab.srMid.szCType, 0, sizeof(srRcpt.unFrm.srOTab.srMid.szCType));

    sprintf(srRcpt.unFrm.srOTab.srMid.szInvNum, "%06ld", pobTran->srBKey.lnInvNum);

    strcpy(acctnum, pobTran->srBRec.szPAN);
    len = strlen(acctnum);
    strncpy(&srRcpt.unFrm.srOTab.srMid.szAcctNum[0], &acctnum[len - LAST4_DIGIT_ACCT], /* bb1 */
           (SML_ACCT_SIZE + 1));
    strcpy(srRcpt.unFrm.srOTab.srMid.szCType, szGetCardAbbrev());

    realbase = (pobTran->srBKey.lnTotalOfTransactionAmount - pobTran->srBRec.lnTipAmount - pobTran->srBRec.lnTaxAmount);
    sprintf(srRcpt.szAmt, "%0ld", realbase);
    vdFormatAmount(srRcpt.szAmt, VS_FALSE);
    vdTrimLeadSpaces(srRcpt.szAmt);

    strlcpy(srRcpt.unFrm.srOTab.srMid.szClerkId, pobTran->srBKey.szClerkId, CLERK_ID_SIZE);
    vdSetTranStatus(pobTran);
}


/*********************************************************************************************
* @func int | inDetailReportOperation |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inDetailReportOperation(TRANSACTION_OBJECT* pobTran) {
    /** /pdebug(("--inDetailReportOperation--"));*/

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    inGetReport1Template();

    return(inPrintDetailReport(pobTran, &obPrinter));
}

/*********************************************************************************************
* @func int | inReprintAnyReceiptOperation |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inReprintAnyReceiptOperation(TRANSACTION_OBJECT* pobTran) {
    /** /pdebug(("--inReprintAnyReceiptOperation--"));*/

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    return(inReprintRecpt(pobTran->srBKey.lnInvNum, &obPrinter, pobTran));
}

/*********************************************************************************************
* @func int | inReprintLastReceiptOperation |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/
#define     REPRINT_LAST_INVOICE        -99L

int inReprintLastReceiptOperation(TRANSACTION_OBJECT* pobTran) {
    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    vdSetPrintReceipt(pobTran, VS_TRUE);
    return (inReprintRecpt(REPRINT_LAST_INVOICE, &obPrinter, pobTran));
}


/*********************************************************************************************
* @func void | vdSetDetailMiddleCondition |
*
*       Sets 'lnMiddleCondition' for Detail Report.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc VOID
*
* @end
**********************************************************************************************/

void vdSetDetailMiddleCondition(TRANSACTION_OBJECT* pobTran) {
    if (inGetPrinterType() == NOPRINTER || !fGetEnablePrinter())
        return;

    lnMiddleCondition = formater_set_flags(0, 0, 0, 0, 0, 0, 0, 0, (fRefundTrans(pobTran) || pobTran->srBKey.fVoided), 0, 0, 0, 0, 0, 0, 0, 0, 0, (inGetTipProcessing() > TIP_OFF || (fGetCashBack())) && (fRefundTrans(pobTran) || pobTran->srBKey.fVoided),  /* added for 460 */
        (inGetTipProcessing() > TIP_OFF || (fGetCashBack())),  /* added for 460 */

        0,
        0,
        0,
        0,

        0,
        0,
        0,
        0,

        0,
        0,
        0,
        0,
        -1);
}

/*********************************************************************************************
* @func static int | inPrintDetailMiddle |
*
* @parm PRINTER_OBJECT *    | obPrinter |
* @parm TRANSACTION_OBJECT *    | pobTran   |
* @parm DETAIL_TOTALS * | psrDetTot |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

static int inPrintDetailMiddle(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran,DETAIL_TOTALS* psrDetTot) {
    /* For Advice Upload requests invoice number needs to be
    picked up from the batch record - Field62 will be loaded
    from the batch record before this function is called
    */
    vdMakeDetailMiddle(pobTran, psrDetTot);
    vdSetDetailMiddleCondition(pobTran);

    return(inPrintLines(obPrinter, DETAIL_MIDDLE_START, DETAIL_MIDDLE_END, NO_BL_LINE, lnMiddleCondition));
}


/*********************************************************************************************
* @func void | vdSetDetailBottomCondition |
*
*       Sets 'lnBottomCondition' for Detail Report.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
* @parm int     | inPrintDetail |
* @parm int     | inNumberOfRecordsinBatch  |
* @parm int     | inGrandTotal  |
* @parm DETAIL_TOTALS * | psrDetTot |
*
* @rdesc VOID
*
* @end
**********************************************************************************************/

void vdSetDetailBottomCondition(TRANSACTION_OBJECT* pobTran,int inPrintDetail,int inNumberOfRecordsinBatch,int inGrandTotal,DETAIL_TOTALS* psrDetTot) {
    lnBottomCondition = formater_set_flags((inPrintDetail), (inNumberOfRecordsinBatch == 0), 0, 0, (inGetTipProcessing() > TIP_OFF),
        (fGetCashBack()),
        (inGetSurCharge()),
        (fGetTaxProc() || psrDetTot->inTaxCnt),

        0,
        0,
        0,
        0,

        0,
        0,
        0,
        0,

        0,
        0,
        0,
        0,

        0,
        0,
        0,
        0,

        0,
        0,
        0,
        0,

        (inGrandTotal == 2),
        (inGrandTotal == 1),
        0,
        0, -1);
}

/*********************************************************************************************
* @func int | inAccumDetailTotals |
*
* @parm DETAIL_TOTALS * | psrAccumTot   |
* @parm DETAIL_TOTALS * | psrDetTot |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
* @end
**********************************************************************************************/

int inAccumDetailTotals(DETAIL_TOTALS* psrAccumTot,DETAIL_TOTALS* psrDetTot) {
    /** /pdebug(("--inAccumDetailTotals--"));*/

    psrAccumTot->inSaleCnt += psrDetTot->inSaleCnt;
    psrAccumTot->inTipCnt += psrDetTot->inTipCnt;
    psrAccumTot->inRefCnt += psrDetTot->inRefCnt;
    psrAccumTot->inCBackCnt += psrDetTot->inCBackCnt;
    psrAccumTot->inGrandCnt += psrDetTot->inGrandCnt;
    psrAccumTot->inSurchgCnt += psrDetTot->inSurchgCnt;
    psrAccumTot->inTaxCnt += psrDetTot->inTaxCnt;
    psrAccumTot->inVoidCnt += psrDetTot->inVoidCnt;
    psrAccumTot->dbSaleAmt += psrDetTot->dbSaleAmt;
    psrAccumTot->dbTipAmt += psrDetTot->dbTipAmt;
    psrAccumTot->dbRefAmt += psrDetTot->dbRefAmt;
    psrAccumTot->dbCBAmt += psrDetTot->dbCBAmt;
    psrAccumTot->dbGrandAmt += psrDetTot->dbGrandAmt;
    psrAccumTot->dbSurCharge += psrDetTot->dbSurCharge;
    psrAccumTot->dbTaxAmt += psrDetTot->dbTaxAmt;
    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inZeroDetailTotals |
*
* @parm DETAIL_TOTALS * | psrDetTot |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
* @end
**********************************************************************************************/

int inZeroDetailTotals(DETAIL_TOTALS* psrDetTot) {
    /** /pdebug(("--inZeroDetailTotals--"));*/

    psrDetTot->inSaleCnt = 0;
    psrDetTot->inTipCnt = 0;
    psrDetTot->inRefCnt = 0;
    psrDetTot->inCBackCnt = 0;
    psrDetTot->inGrandCnt = 0;
    psrDetTot->inSurchgCnt = 0;
    psrDetTot->inTaxCnt = 0;
    psrDetTot->inVoidCnt = 0;
    psrDetTot->dbSaleAmt = 0.0;
    psrDetTot->dbTipAmt = 0.0;
    psrDetTot->dbRefAmt = 0.0;
    psrDetTot->dbCBAmt = 0.0;
    psrDetTot->dbGrandAmt = 0.0;
    psrDetTot->dbSurCharge = 0.0;
    psrDetTot->dbTaxAmt = 0.0;
    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inSetDetailPrintTotals |
*
* @parm DETAIL_TOTALS * | psrDetTot |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
* @end
**********************************************************************************************/

int inSetDetailPrintTotals(DETAIL_TOTALS* psrDetTot) {
    /** /pdebug(("--inSetDetailPrintTotals--"));*/

    sprintf(srRcpt.unFrm.srDet.srMid.szTotalSaleCnt, SUBSTITUTE_D, psrDetTot->inSaleCnt);
    sprintf(srRcpt.unFrm.srDet.srMid.szTotalTipCnt, SUBSTITUTE_D, psrDetTot->inTipCnt);
    sprintf(srRcpt.unFrm.srDet.srMid.szTotalCBackCnt, SUBSTITUTE_D, psrDetTot->inCBackCnt);
    sprintf(srRcpt.unFrm.srDet.srMid.szTotalSurchgCnt, SUBSTITUTE_D, psrDetTot->inSurchgCnt);
    sprintf(srRcpt.unFrm.srDet.srMid.szTotalTaxCnt, SUBSTITUTE_D, psrDetTot->inTaxCnt);
    sprintf(srRcpt.unFrm.srDet.srMid.szTotalRefCnt, SUBSTITUTE_D, psrDetTot->inRefCnt);
    sprintf(srRcpt.unFrm.srDet.srMid.szGrandCnt, SUBSTITUTE_D, psrDetTot->inGrandCnt);
    /*
        sprintf(srRcpt.unFrm.srDet.srMid.szGrandTotal,SUBSTITUTE_LD, psrDetTot->lnGrandAmt);
        sprintf(srRcpt.unFrm.srDet.srMid.szTotalSaleAmt,SUBSTITUTE_LD, psrDetTot->lnSaleAmt);
        sprintf(srRcpt.unFrm.srDet.srMid.szTotalRefund,SUBSTITUTE_LD, psrDetTot->lnRefAmt);
        sprintf(srRcpt.unFrm.srDet.srMid.szTotalCBAmt,SUBSTITUTE_LD, psrDetTot->lnCBAmt);
        sprintf(srRcpt.unFrm.srDet.srMid.szTotalSchgAmt,SUBSTITUTE_LD, psrDetTot->lnSurCharge);
        sprintf(srRcpt.unFrm.srDet.srMid.szTotalTaxAmt,SUBSTITUTE_LD, psrDetTot->lnTaxAmt);
        sprintf(srRcpt.unFrm.srDet.srMid.szTotalTipAmt,SUBSTITUTE_LD, psrDetTot->lnTipAmt);
    */
    vdDb2Str(psrDetTot->dbGrandAmt, srRcpt.unFrm.srDet.srMid.szGrandTotal);
    vdTrimLeadSpaces(srRcpt.unFrm.srDet.srMid.szGrandTotal);

    vdDb2Str(psrDetTot->dbSaleAmt, srRcpt.unFrm.srDet.srMid.szTotalSaleAmt);
    vdTrimLeadSpaces(srRcpt.unFrm.srDet.srMid.szTotalSaleAmt);

    vdDb2Str(psrDetTot->dbRefAmt, srRcpt.unFrm.srDet.srMid.szTotalRefund);
    vdTrimLeadSpaces(srRcpt.unFrm.srDet.srMid.szTotalRefund);

    vdDb2Str(psrDetTot->dbCBAmt, srRcpt.unFrm.srDet.srMid.szTotalCBAmt);
    vdTrimLeadSpaces(srRcpt.unFrm.srDet.srMid.szTotalCBAmt);

    vdDb2Str(psrDetTot->dbSurCharge, srRcpt.unFrm.srDet.srMid.szTotalSchgAmt);
    vdTrimLeadSpaces(srRcpt.unFrm.srDet.srMid.szTotalSchgAmt);

    vdDb2Str(psrDetTot->dbTaxAmt, srRcpt.unFrm.srDet.srMid.szTotalTaxAmt);
    vdTrimLeadSpaces(srRcpt.unFrm.srDet.srMid.szTotalTaxAmt);

    vdDb2Str(psrDetTot->dbTipAmt, srRcpt.unFrm.srDet.srMid.szTotalTipAmt);
    vdTrimLeadSpaces(srRcpt.unFrm.srDet.srMid.szTotalTipAmt);

    if ((strlen(srRcpt.unFrm.srDet.srMid.szGrandTotal) <= 3) && (str2int(srRcpt.unFrm.srDet.srMid.szGrandTotal) < 0))
        sprintf(&srRcpt.unFrm.srDet.srMid.szGrandTotal[1], "%03li", (-1L) * str2long(srRcpt.unFrm.srDet.srMid.szGrandTotal));

    vdFormatAmount(srRcpt.unFrm.srDet.srMid.szGrandTotal, VS_TRUE);
    vdFormatAmount(srRcpt.unFrm.srDet.srMid.szTotalSaleAmt, VS_TRUE);
    vdFormatAmount(srRcpt.unFrm.srDet.srMid.szTotalRefund, VS_TRUE);
    vdFormatAmount(srRcpt.unFrm.srDet.srMid.szTotalCBAmt, VS_TRUE);
    vdFormatAmount(srRcpt.unFrm.srDet.srMid.szTotalSchgAmt, VS_TRUE);
    vdFormatAmount(srRcpt.unFrm.srDet.srMid.szTotalTaxAmt, VS_TRUE);
    vdFormatAmount(srRcpt.unFrm.srDet.srMid.szTotalTipAmt, VS_TRUE);

    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func static void | vdSetOpenTabHeaderCondition |
*
*       Sets 'lnHeaderCondition' for Open Tab Report.
*
* @parm int     | inReportType  |
*
* @rdesc VOID
*
* @end
**********************************************************************************************/

static void vdSetOpenTabHeaderCondition(int inReportType) {
    if (inGetPrinterType() == NOPRINTER || !fGetEnablePrinter())
        return;

    lnHeaderCondition = formater_set_flags(inReportType, (fGetDemoMode() == VS_TRUE), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (inGetTipProcessing() == TIP_OFF), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1);
}

/*********************************************************************************************
* @func static void | vdSetOpenTabBottomCondition |
*
*       Sets 'lnBottomCondition' for Open Tab Report.
*
* @parm int     | inCount   |
*
* @rdesc VOID
* @end
**********************************************************************************************/

static void vdSetOpenTabBottomCondition(int inCount) {
    /** /pdebug(("--vdSetOpenTabBottomCondition--"));*/

    if (inGetPrinterType() == NOPRINTER || !fGetEnablePrinter())
        return;

    lnBottomCondition = formater_set_flags(0, (inCount > 0),
                        0,
                        0,

                        0,
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        0,


                        0,
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        0,

                        0,
                        0,
                        0,
                        0, -1);
}

/*********************************************************************************************
* @func static int | inPrintOpenTabReport |
*
*       Browse through the open tab batch and prints open tab report.
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
* @parm PRINTER_OBJECT *    | obPrinter |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

static int inPrintOpenTabReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter) {
    int inCurrentBatchRecord = 0;
    int inNumberOfRecordsinBatch = 0;
    int inOpenTabReport = VS_TRUE;

    inNumberOfRecordsinBatch = inGetOBatchRecCnt(pobTran);

    /* Check whether the batch is empty or not */
    if (inNumberOfRecordsinBatch == 0) {
        vdDisplayMessageFromFile(BATCH_EMPTY_MSG, WARNING_MSG);
        return(VS_ERR);
    }

    if (fGetEnablePrinter())
        vdDisplayMessageFromFile(PRINTING_MSG, STATUS_MSG);
    /* added this call to incorporate 06/22/99 base change 09/23/99 gw */

    vdMakeReportHeader(pobTran);
    inPrintReceiptHeader(pobTran);

    vdSetOpenTabHeaderCondition(inOpenTabReport);
    if (inPrintLines(obPrinter, OPENTAB_TOP_START, OPENTAB_TOP_END, NO_BL_LINE, lnHeaderCondition) != VS_SUCCESS)
        return(VS_ERR);

    for (inCurrentBatchRecord = 0; inCurrentBatchRecord < inNumberOfRecordsinBatch; inCurrentBatchRecord++) {
        if (inLoadOBatchRec(pobTran, inCurrentBatchRecord) != VS_SUCCESS)
            return (VS_ERR);

        vdMakeOpenTabMiddle(pobTran);
        if (inPrintLines(obPrinter, OPENTAB_MIDDLE_START, OPENTAB_MIDDLE_END, NO_BL_LINE, lnMiddleCondition) != VS_SUCCESS)
            return(VS_ERR);

        if (act_kbd_pending_test(KEY_CANCEL))
            return(VS_ESCAPE);
    }
    /* Bottom */

    memset(srRcpt.szErrorMessage, '\0', sizeof(srRcpt.szErrorMessage));
    memset(srRcpt.szStatusMessage, '\0', sizeof(srRcpt.szStatusMessage));

    vdSetOpenTabBottomCondition(inNumberOfRecordsinBatch);
    if (inPrintLines(obPrinter, OPENTAB_BOTTOM_START, OPENTAB_BOTTOM_END, NO_BL_LINE, lnBottomCondition) != VS_SUCCESS)
        return(VS_ERR);

    return(VS_SUCCESS);
}


/*********************************************************************************************
* @func int | inOpenTabReportOperation |
*
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

int inOpenTabReportOperation(TRANSACTION_OBJECT* pobTran) {
    /*    pdebug(("--inOpenTabReportOperation--"));*/

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }
    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    inGetReport1Template();

    return(inPrintOpenTabReport(pobTran, &obPrinter));
}

/*********************************************************************************************
* @func static int | inReprintRecpt |
*
*       This function is changed to be used to re-print LAST
*       receipt also, in addition to re-print the transactions in
*       the batch. If the invoice number is ZERO, it is considered
*       as "Reprint last receipt".
*
* @parm long    | lnInvNum  |
* @parm PRINTER_OBJECT *    | obPrinter |
* @parm TRANSACTION_OBJECT *    | pobTran   |
*
* @rdesc Return values.
*
* @flag int    |    VS_SUCCESS
*                   VS_ESCAPE
*                   VS_ERR
* @end
**********************************************************************************************/

static int inReprintRecpt(long lnInvNum,PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran) {
    int inResult;
    DB_FILE dbReprintFile;

    pdebug(("--inReprintRecpt--"));

    if (inGetPrinterType() == NOPRINTER && fGetEnablePrinter()) {
        vdDisplayMessageFromFile(NO_PRINTER_MSG, WARNING_MSG);
        return(VS_SUCCESS);
    }

    if (!fGetEnablePrinter())
        return(VS_SUCCESS);

    pobTran->srBKey.lnInvNum = lnInvNum;

    if (lnInvNum == REPRINT_LAST_INVOICE)             /* Reprint LAST receipt */ {
        /** /pdebug(("Reprint last receipt"));*/


        if (inOpenBatch(&dbReprintFile, REPRINT_FILE_NAME) != VS_SUCCESS) {

            vdSGErrorMessage(BATCH_ERR_MSG);
            return(VS_ERR);
        }
        if (inReadReprintBatchData(&dbReprintFile, &pobTran->srBKey, &pobTran->srBRec, 0L) != VS_SUCCESS) {
            vdSGErrorMessage(NO_DATA_MSG);
            inCloseBatch(&dbReprintFile);
            return(VS_ERR);
        }

        if (inCloseBatch(&dbReprintFile) != VS_SUCCESS) {

            vdSGErrorMessage(BATCH_ERR_MSG);
            return(VS_ERR);
        }

        inLoadMITRec(pobTran->srBRec.inMerchantIndex);

        inLoadCardCurrenyHostData(pobTran);

        /* In CoreFix, if you remove the call to inLoadDefaultCurrency(), */
        /* which reloads the CST with the HDT currency index, in */
        /* inLoadCDTandCST() then the patch below is not needed.   */
        /* 08/08/00 - mdm */

        /* The CoreFix wasn't quite made, the original inLoadCDTandCST() */
        /* function was just renamed inLoadCardCurrenyHostData() so this */
        /* patch is still needed for now - 08/22/00 */

        /* Load the correct currency for this record, multi-currency error */
        if (inLoadCSTRec(pobTran->srBKey.inCurrencyIndex) != VS_SUCCESS) {
            vdDisplayMessageFromFile(CST_ERR_MSG, WARNING_MSG);
            return(VS_ERR);
        }
    } else {
        pdebug(("Reprint any receipt"));

        /*
         *      Search Data Capture batch first, then Open Tab batch.
         */
        if (inGetDCInvBatchRec(pobTran, KEY_ALL_RECS, DB_FIRST) != VS_SUCCESS) {
            vdBatchOTOpen(pobTran);
            inResult = inGetOTInvBatchRec(pobTran, KEY_ALL_RECS, DB_FIRST);
            vdCloseTabBatch(pobTran);
            if (inResult != VS_SUCCESS) {
                /**/pdebug(("Not in Tab Batch Either"));/**/
                vdDisplayErrorMessage(NO_MATCH_MSG21);
                return(VS_ERR);
            }
        } /* end if not found in DC batch */


        /* In CoreFix, if you remove the call to inLoadDefaultCurrency(), */
        /* which reloads the CST with the HDT currency index, in */
        /* inLoadCDTandCST() then the patch below is not needed.   */
        /* inLoadCDTandCST() is called by inGetDCInvBatchRec() and */
        /* inGetOTInvBatchRec() above.  08/08/00 - mdm */

        /* The CoreFix wasn't quite made, the original inLoadCDTandCST() */
        /* function was just renamed inLoadCardCurrenyHostData() so this */
        /* patch is still needed for now - 08/22/00 */

        /* Load the correct currency for this record, multi-currency error */
        if (inLoadCSTRec(pobTran->srBKey.inCurrencyIndex) != VS_SUCCESS) {
            vdDisplayMessageFromFile(CST_ERR_MSG, WARNING_MSG);
            return(VS_ERR);
        }
    } /* end else reprint any receipt */

    inGetReceiptTemplate(pobTran);
    if (inChkPrinterStatus(obPrinter) != VS_SUCCESS)
        return(VS_ERR);

    vdMakeFooter(pobTran);
    vdBuildReceipt(pobTran);
    pobTran->srBRec.inPrintOption = PRT_MERCH | PRT_DUPLICATE;
    if ((inResult = inRunFormSegments(pobTran, REPRINT_RECEIPT)) != VS_SUCCESS)
        return(VS_ERR);

    return(VS_SUCCESS);
}

#undef VSREPT1_C

#endif // BATCH_DEFINED
